package com.avira.smstest;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.os.Parcel;
import android.os.Parcelable;

public class SMSObject implements Parcelable
{
	public static final String EMPTY = "";
	public static final long NO_TIMESTAMP = 0L;
	
	private String m_sender;
	private String m_contents;
	private long m_timestamp;
	
	public static final Parcelable.Creator<SMSObject> CREATOR = new Parcelable.Creator<SMSObject>() 
	{
        public SMSObject createFromParcel(Parcel in)
        {
            return new SMSObject(in); 
        }

        public SMSObject[] newArray(int size)
        {
            return new SMSObject[size];
        }
    };
	
    public SMSObject(String sender, String contents, long timestamp)
    {
    	setSender(sender);
		setContents(contents);
		setTimestamp(timestamp);
	}
    
    public SMSObject()
    {
    	this(EMPTY, EMPTY, NO_TIMESTAMP);
    }
    
	public SMSObject(Parcel in)
	{
		setSender(in.readString() );
		setContents(in.readString() );
		setTimestamp(in.readLong() );
	}
	
	public int describeContents()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags)
	{
		dest.writeString(m_sender);
		dest.writeString(m_contents);
		dest.writeLong(m_timestamp);
	}
	
	//setters - null allowed
	public String setSender(String sender)
	{
		this.m_sender = sender;
		return getSender();
	}
	
	public String setContents(String contents)
	{
		this. m_contents = contents;
		return getContents();
	}
	
	public long setTimestamp(long timestamp)
	{
		this.m_timestamp = timestamp;
		return getTimestamp();
	}
	
	//getters
	public String getSender()
	{
		return m_sender;
	}
	
	public String getContents()
	{
		return m_contents;
	}
	
	public long getTimestamp()
	{
		return m_timestamp;
	}
	
	public String getDate()
	{
		SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.US); 
        return df.format(new Date(getTimestamp() ) );
	}
	
	public String getHour()
	{
		SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss", Locale.US);
		return df.format(new Date(getTimestamp() ) );
	}

}
